package com.lzb.musicplayer.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lzb.basic.dialog.BaseSmartDialog;
import com.lzb.musicplayer.R;
import com.lzb.musicplayer.databinding.DialogRingtoneBinding;
import com.lzb.musicplayer.databinding.DialogSaveRingtoneBinding;


public class RingtoneDialog extends BaseSmartDialog<DialogRingtoneBinding> implements View.OnClickListener {

    private String text;

    public void setText(String text) {
        this.text = text;
    }

    public RingtoneDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_ringtone;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.ivCancel.setOnClickListener(this);
        mDataBinding.tvStandardRingtone.setOnClickListener(this);
        mDataBinding.tvNotificationSound.setOnClickListener(this);
        mDataBinding.tvAlarmSound.setOnClickListener(this);
        mDataBinding.tvAssignContact.setOnClickListener(this);
        mDataBinding.tvShare.setOnClickListener(this);
        mDataBinding.tvDelete.setOnClickListener(this);

        if (!TextUtils.isEmpty(text)) {
            mDataBinding.tvTitle.setText(text);
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ivCancel) {
            dismiss();
        } else if (id == R.id.tvStandardRingtone) {
            dismiss();
            if (listener != null) {
                listener.clickItem(0);
            }
        } else if (id == R.id.tvNotificationSound) {
            dismiss();
            if (listener != null) {
                listener.clickItem(1);
            }
        } else if (id == R.id.tvAlarmSound) {
            dismiss();
            if (listener != null) {
                listener.clickItem(2);
            }
        } else if (id == R.id.tvAssignContact) {
            dismiss();
            if (listener != null) {
                listener.clickItem(3);
            }
        } else if (id == R.id.tvShare) {
            dismiss();
            if (listener != null) {
                listener.clickShare();
            }
        } else if (id == R.id.tvDelete) {
            dismiss();
            if (listener != null) {
                listener.clickDelete();
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickItem(int pos);

        void clickShare();

        void clickDelete();
    }
}
